package com.jinyu.jyly.ui.mine.passageway;

import android.view.View;
import android.widget.ImageView;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.qmuiteam.qmui.util.QMUIStatusBarHelper;
import com.jinyu.jyly.R;
import com.jinyu.jyly.base.BaseActivity;
import com.jinyu.jyly.bean.AllInfoBean;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 新人竞拍
 */
public class PassageNewerWayActivity extends BaseActivity<PassageNewerPresenter> implements PassageNewsContract.View {

    @BindView(R.id.fake_status_bar)
    View fakeStatusBar;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tablayout)
    TabLayout tablayout;
    @BindView(R.id.viewpager)
    ViewPager viewpager;


    private PassageNewerPresenter presenter;

    @Override
    public int getLayout() {
        return R.layout.activity_passage_newer;
    }

    @Override
    protected PassageNewerPresenter getPresenter() {
        if (presenter == null) {
            presenter = new PassageNewerPresenter(this, this);
        }
        return presenter;
    }

    @Override
    protected void initEventAndData() {
        QMUIStatusBarHelper.translucent(this);
        QMUIStatusBarHelper.setStatusBarDarkMode(this);

        tablayout.setTabMode(TabLayout.MODE_FIXED);
        tablayout.setTabGravity(TabLayout.GRAVITY_FILL);

        MyPagerAdapter myPagerAdapter = new MyPagerAdapter(getSupportFragmentManager());
        viewpager.setOffscreenPageLimit(3);
        viewpager.setAdapter(myPagerAdapter);
        tablayout.setupWithViewPager(viewpager);

    }


    @Override
    public void onFailer(Throwable throwable) {

    }

    @Override
    public void onAddNewGreen(AllInfoBean infoBean) {

    }


    @OnClick({R.id.iv_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
        }
    }

    class MyPagerAdapter extends FragmentPagerAdapter {

        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position){
                case 0:
                    return "第一场";
                case 1:
                    return "第二场";
                default:
                    return "第三场";
            }
        }

        @Override
        public Fragment getItem(int position) {
            if(position == 0){
                return PassageNewerTabFragment.newInstance(1);//mUser_score
            }else if(position == 1){
                return PassageNewerTabFragment.newInstance(2);//mUser_score
            }else{
                return PassageNewerTabFragment.newInstance(3);//mUser_score
            }
        }

        @Override
        public int getCount() {
            return 1;
        }

    }
}
